﻿using System.Collections.Generic;
using System;

namespace QuakeStats
{
    class LogEntry
    {
        #region CONSTANTS
        private const string CLIENTUSERINFO = "ClientUserinfoChanged";
        private const string ITEM = "Item";
        private const string KILL = "Kill";
        private const string INITGAME = "InitGame";
        private const string WARMUP = "Warmup";
        private const string CLIENTCONNECT = "ClientConnect";
        private const string CLIENTBEGIN = "ClientBegin";
        private const string CLIENTDISCONNECT = "ClientDisconnect";
        private const string SHUTDOWNGAME = "ShutdownGame";
        private const string EXIT = "Exit";
        private const string SCORE = "score";
        private const string TEAMSCORE = "red";
        private const string SAY = "say";
        private const string SAYTEAM = "sayteam";
        private const string DASH = "------------------------------------------------------------";
        #endregion

        public string Time { get; set; }
        public LogEntryType LogEntryType { get; set; }
        
        public DateTime MasterTime
        {
            get 
            {
                return Program.MasterDate.AddMinutes(int.Parse(Time.Split(':')[0]) + Program.TimeDifference).AddSeconds(int.Parse(Time.Split(':')[1]));
            }
        }

        public string Data { get; set; }

        protected string RawLine;

        public LogEntry(string line)
        {
            RawLine = line;
            ParseTime(RawLine);
            LogEntryType = GetLogEntryType(RawLine);
            ParseLineData(RawLine);
        }

        public void Initialize()
        {
            
        }

        protected Dictionary<string, string> CreateDictionary(string data)
        {
            string[] splitValues = data.Split('\\');
            Dictionary<string, string> dataValues = new Dictionary<string, string>(splitValues.Length / 2);

            for (int x = 0; x < splitValues.Length; x++)
            {
                dataValues.Add(splitValues[x], splitValues[x + 1]);
                x++;
            }

            return dataValues;
        }


        protected virtual void ParseLineData(string line)
        {

            switch (LogEntryType)
            {
                case LogEntryType.ClientUserInfo:
                    break;
                case LogEntryType.Item:
                    break;
                case LogEntryType.Kill:
                    break;
                case LogEntryType.InitGame:
                    break;
                case LogEntryType.Warmup:
                    break;
                case LogEntryType.ClientConnect:
                    break;
                case LogEntryType.ClientBegin:
                    break;
                case LogEntryType.ShutdownGame:
                    break;
                case LogEntryType.Dash:
                    break;
                case LogEntryType.ClientDisconnect:
                    break;
                case LogEntryType.Exit:
                    break;
                case LogEntryType.Score:
                    break;
                case LogEntryType.TeamScore:
                    break;
                case LogEntryType.Say:
                    break;
                case LogEntryType.SayTeam:
                    break;
                default:
                    break;


            }
        }

        private void ParseTime(string line)
        {
            Time = line.Trim().Substring(0, line.Trim().IndexOf(":") + 3).Trim();
        }

        public static LogEntryType GetLogEntryType(string line)
        {
            string lineTypeString = line.Trim().Substring(line.Trim().Substring(0, line.Trim().IndexOf(":") + 3).Trim().Length).Trim().Split(':')[0];
            switch (lineTypeString)
            {
                case CLIENTUSERINFO:
                    return LogEntryType.ClientUserInfo;
                case ITEM:
                    return LogEntryType.Item;
                case KILL:
                    return LogEntryType.Kill;
                case INITGAME:
                    return LogEntryType.InitGame;
                case WARMUP:
                    return LogEntryType.Warmup;
                case CLIENTCONNECT:
                    return LogEntryType.ClientConnect;
                case CLIENTBEGIN:
                    return LogEntryType.ClientBegin;
                case SHUTDOWNGAME:
                    return LogEntryType.ShutdownGame;
                case DASH:
                    return LogEntryType.Dash;
                case CLIENTDISCONNECT:
                    return LogEntryType.ClientDisconnect;
                case EXIT:
                    return LogEntryType.Exit;
                case SCORE:
                    return LogEntryType.Score;
                case TEAMSCORE:
                    return LogEntryType.TeamScore;
                case SAY:
                    return LogEntryType.Say;
                case SAYTEAM:
                    return LogEntryType.SayTeam;
                default:
                    return LogEntryType.Unimportant;
            }
        }
    }


}
